﻿using System;
using System.Windows.Forms;

namespace GeoSketch2.Core
{
    public partial class GeoSketchMainForm : Form
    {
        #region Constructor
        /// <summary>
        /// The main form of the application, the parent MDI form
        /// </summary>
        public GeoSketchMainForm()
        {
            InitializeComponent();
        }
        #endregion

        #region MenuToolbarActions
        /// <summary>
        /// The action when clicking the new button
        /// </summary>
        public virtual void New(object sender, EventArgs e)
        {
            ((GeoSketchForm)(this.ActiveMdiChild)).MDIParentNew();
        }

        /// <summary>
        /// The action when clicking the open button
        /// </summary>
        public virtual void OpenFile(object sender, EventArgs e)
        {
            ((GeoSketchForm)(this.ActiveMdiChild)).MDIParentOpen();
        }

        /// <summary>
        /// The action when clicking the save as menu
        /// </summary>
        public virtual void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ((GeoSketchForm)(this.ActiveMdiChild)).MDIParentSaveAs();
        }

        /// <summary>
        /// The action when clicking the exit menu
        /// </summary>
        public virtual void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        /// <summary>
        /// The action when clicking the cut menu
        /// </summary>
        public virtual void CutToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        /// <summary>
        /// The action when clicking the copy menu
        /// </summary>
        public virtual void CopyToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        /// <summary>
        /// The action when clicking the paste menu
        /// </summary>
        public virtual  void PasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        /// <summary>
        /// The action when clicking the toolbar menu
        /// </summary>
        public virtual void ToolBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ParentToolbar.Visible = toolBarToolStripMenuItem.Checked;
        }

        /// <summary>
        /// The action when clicking the status bar menu
        /// </summary>
        public virtual void StatusBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ParentStatusStrip.Visible = statusBarToolStripMenuItem.Checked;
        }

        /// <summary>
        /// The action when clicking the cascade menu
        /// </summary>
        public virtual void CascadeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.Cascade);
        }

        /// <summary>
        /// The action when clicking the tile vertical menu
        /// </summary>
        public virtual void TileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical);
        }

        /// <summary>
        /// The action when clicking the tile horizontal menu
        /// </summary>
        public virtual void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        /// <summary>
        /// The action when clicking the arrange icons menu
        /// </summary>
        public virtual void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.ArrangeIcons);
        }

        /// <summary>
        /// The action when clicking the close all menu
        /// </summary>
        public virtual void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form childForm in MdiChildren)
            {
                childForm.Close();
            }
        }

        /// <summary>
        /// The action when clicking the print button
        /// </summary>
        public virtual void printToolStripButton_Click(object sender, EventArgs e)
        {
            ((GeoSketchForm)(this.ActiveMdiChild)).MDIParentPrint();
        }

        /// <summary>
        /// The action when clicking the print preview button
        /// </summary>
        public virtual void printPreviewToolStripButton_Click(object sender, EventArgs e)
        {
            ((GeoSketchForm)(this.ActiveMdiChild)).MDIParentPrintPreview();
        }

        /// <summary>
        /// The action when clicking the help button
        /// </summary>
        public virtual void helpToolStripButton_Click(object sender, EventArgs e)
        {
            ((GeoSketchForm)(this.ActiveMdiChild)).MDIParentHelp();
        }
        #endregion

        #region Methods
        /// <summary>
        /// Activates the items required by the child form
        /// </summary>
        public void SetActiveItems(ActiveMDIParentItems Items)
        {
            newToolStripButton.Enabled = newToolStripMenuItem.Enabled = Items.New;
            openToolStripButton.Enabled = openToolStripMenuItem.Enabled = Items.Open;
            saveToolStripButton.Enabled = saveToolStripMenuItem.Enabled = saveAsToolStripMenuItem.Enabled = Items.Save;
            printToolStripButton.Enabled = printToolStripMenuItem.Enabled = Items.Print;
            printPreviewToolStripButton.Enabled = printPreviewToolStripMenuItem.Enabled = Items.PrintPreview;
            helpToolStripButton.Enabled = contentsToolStripMenuItem.Enabled = indexToolStripMenuItem.Enabled = searchToolStripMenuItem.Enabled = Items.Help;
            undoToolStripMenuItem.Enabled = Items.Undo;
            redoToolStripMenuItem.Enabled = Items.Redo;
            cutToolStripMenuItem.Enabled = Items.Cut;
            copyToolStripMenuItem.Enabled = Items.Copy;
            pasteToolStripMenuItem.Enabled = Items.Paste;
        }

        private void SaveFile(object sender, EventArgs e)
        {
            if (this.ActiveMdiChild != null)
            {
                ((GeoSketchForm)(this.ActiveMdiChild)).MDIParentSave();
            }
        }
        #endregion
    }
}
